package io.alvin.jframework.plugin.security.realm;

import io.alvin.jframework.helper.DatabaseHelper;
import io.alvin.jframework.plugin.security.SecurityConfig;
import io.alvin.jframework.plugin.security.password.Md5CredentialsMatcher;
import org.apache.shiro.realm.jdbc.JdbcRealm;

/**
 * 需要提供 security.jdbc.* 配置项
 *
 * Created by Alvin on 2017/7/15.
 */
public class DefaultJdbcRealm extends JdbcRealm {

    public DefaultJdbcRealm() {
        super.setDataSource(DatabaseHelper.getDataSource());
        super.setAuthenticationQuery(SecurityConfig.getJdbcAuthcQuery());
        super.setUserRolesQuery(SecurityConfig.getJdbcRolesQuery());
        super.setPermissionsQuery(SecurityConfig.getJdbcPermissionQuery());
        super.setPermissionsLookupEnabled(true);
        super.setCredentialsMatcher(new Md5CredentialsMatcher()); // 使用MD5加密算法
    }
}
